//
//  ViewController.m
//  WebTap
//
//  Created by UUU on 16/8/26.
//  Copyright © 2016年 CheDan. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>
@property (strong, nonatomic)  UIWebView *webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.tag = 1000;
    
    
    self.webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    self.webView.tag = 555;
    self.webView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.webView];
    
    
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
    singleTapGestureRecognizer.delegate  = self;
    singleTapGestureRecognizer.cancelsTouchesInView = NO;
    singleTapGestureRecognizer.numberOfTapsRequired = 1;
    singleTapGestureRecognizer.numberOfTouchesRequired = 1;
    [self.webView addGestureRecognizer:singleTapGestureRecognizer];

    
    UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
    doubleTapGestureRecognizer.delegate  = self;
    doubleTapGestureRecognizer.cancelsTouchesInView = NO;
    singleTapGestureRecognizer.numberOfTouchesRequired = 1;
    [doubleTapGestureRecognizer setNumberOfTapsRequired:2];
    [self.webView addGestureRecognizer:doubleTapGestureRecognizer];
    
    [singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTapGestureRecognizer];
//    GeneralBtn_close.png
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"button" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor redColor];
    button.tag = 666;
    CGFloat width = self.view.frame.size.width;
    button.frame = CGRectMake((width - 100)/2, 100, 100, 100);
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.webView addSubview:button];
    
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if ([touch.view isKindOfClass:[UIButton class]]){
        return false;
    }
    return true;
}
- (void)buttonAction{
    NSLog(@"buttonAction");
}
- (void)singleTap:(UITapGestureRecognizer *)singleTapGestureRecognizer{
    NSLog(@"singleTapGestureRecognizer ---->单机手势 numberOfTapsRequired 1");
    
    
     NSLog(@"gestureRecognizer %ld",singleTapGestureRecognizer.view.tag);
}

- (void)doubleTap:(UITapGestureRecognizer *)doubleTap{
    NSLog(@"doubleTap --->双击手势 numberOfTapsRequired 2");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
